#!/usr/bin/perl

use warnings;

$0=~m/^(.+)\/[^\/]+$/;
require "$1/config.pl";

$|=1;
my $dbh = db_connect();
my $sth = $dbh->prepare("SELECT traffic_month,limit_month FROM users WHERE user=?") || die "db error: $^E";
my ($traffic_month,$limit_month);

while (<STDIN>) {
    chop;    
    $sth->execute(remove_domain($_)) || die "db error: $^E";
    ($traffic_month,$limit_month) = $sth->fetchrow_array();
    unless ($limit_month) {
        #print "ERR error=Unknown user.\n";
        print "OK\n";
    } else {
        if ($limit_month>$traffic_month) {
            print "OK\n";
        } else {
            print "ERR error=Traffic overlimit. Used=$traffic_month, Limit=$limit_month\n";
        }
    }
}
